a=int(input())
maxprost=0
if a<1000 or a>9999:
    print ("O")
else:
    d1=a//1000
    d2=a//100%10
    d3=a//10%10
    d4=a%10
    print (d1, d2, d3, d4)
    countd=0
    for i in range(1,d1+1):
        if d1%i==0:
            countd+=1
    if countd==2 and d1>maxprost:
        maxprost=d1
    countd=0
    for i in range(1,d2+1):
        if d2%i==0:
            countd+=1
    if countd==2 and d2>maxprost:
        maxprost=d2
    chislo=d1*10+d2
    countd=0
    for i in range(1,d3+1):
        if d3%i==0:
            countd+=1
    if countd==2 and d3>=maxprost:
        maxprost=d3
    countd=0
    for i in range(1,d4+1):
        if d4%i==0:
            countd+=1
    if countd==2 and d4>=maxprost:
        maxprost=d4
    countd=0
    chislo=d1*10+d2
    for i in range(1,chislo+1):
        if chislo%i==0:
            countd+=1
    if countd==2 and chislo>=maxprost:
        maxprost=chislo
    countd=0
    chislo=d1*100+d2*10+d3
    for i in range(1,chislo+1):
        if chislo%i==0:
            countd+=1
    if countd==2 and chislo>=maxprost:
        maxprost=chislo
    countd=0
    chislo=d2*100+d3*10+d4
    for i in range(1, chislo+1):
        if chislo%i==0:
            countd+=1
    if countd==2 and d1>=maxprost:
        maxprost=chislo
    countd=0
    chislo=d3*10+d4
    for i in range(1, chislo+1):
        if chislo%i==0:
            countd+=1
    if countd==2 and chislo>=maxprost:
        maxprost=chislo
    print (maxprost)